package com.kecheng.dao;

import com.kecheng.hibernate.BaseDao;
import com.kecheng.pojo.Skuclassify3;
import org.hibernate.criterion.DetachedCriteria;
import org.hibernate.criterion.MatchMode;
import org.hibernate.criterion.Order;
import org.hibernate.criterion.Restrictions;
import org.springframework.stereotype.Component;

import java.util.List;

@Component
public class Skuclassify3Dao extends BaseDao{

	public List<Skuclassify3> findall() {
		List<?> skuclassify3s=this.getHibernateTemplate().find("from Skuclassify2");
		return (List<Skuclassify3>) skuclassify3s;
	}
	public List<Skuclassify3> findBySkuclassifyid2(int skuclassifyid2) {
		List<Skuclassify3> skuclassify3s= (List<Skuclassify3>) this.getHibernateTemplate().find("from Skuclassify3 where skuclassifyid2=?",skuclassifyid2);
		return skuclassify3s;
	}
	public Skuclassify3 findById(int id) {
		List<Skuclassify3> skuclassify3s= (List<Skuclassify3>) this.getHibernateTemplate().find("from Skuclassify3 where id = ?",id);
		if(skuclassify3s.size()>0){
			Skuclassify3 Skuclassify3=skuclassify3s.get(0);
			return Skuclassify3;
		}
		return null;
	}
	
	public List<Skuclassify3> findmh(String name,int refid) {
		// TODO Auto-generated method stub
		DetachedCriteria criteria=DetachedCriteria.forClass(Skuclassify3.class);
		criteria.add(
				Restrictions.ilike("name", name, MatchMode.ANYWHERE));	
		criteria.addOrder(Order.desc("id"));
		criteria.add(Restrictions.eq("skuclassifyid2", refid));
		List<Skuclassify3> skuclassify3s= (List<Skuclassify3>) this.getHibernateTemplate().findByCriteria(criteria);
		return skuclassify3s;
	}

}
